package client.comm.baoding

import android.content.IntentFilter
import android.os.Bundle
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import client.comm.commlib.base.BaseActivity
import client.comm.commlib.base.FinishReciver
import client.comm.baoding.ui.LoginActivity

abstract class BaseMiddleActivity<VM : ViewModel, V : ViewDataBinding> : BaseActivity<VM, V>() {

    var receiver: FinishReciver? = null

    override fun onPostCreate(savedInstanceState: Bundle?) {
        super.onPostCreate(savedInstanceState)
        if (this !is LoginActivity) {
            val intentFilter = IntentFilter()
            receiver = FinishReciver()
            intentFilter.addAction(FinishReciver.FINISH_ACTION)
            registerReceiver(receiver, intentFilter)
        }
    }

    override fun onDestroy() {
        receiver?.let {
            unregisterReceiver(it)
        }
        super.onDestroy()
    }

}